<?php
class defaultApp extends Control {
	/**
	 * 后台首页，展示登录表单
	 */
	function index(){
		$this->layout = 'login';
		
		$this->add_css('inlog');
		$this->display();
	}
	
	/**
	 * 验证用户登录信息
	 */
	function login() {
		$user_name = isset($_POST['username']) ? trim($_POST['username']) : "";
		$password = isset($_POST['password']) ? trim($_POST['password']) : "";
	
		$user_model = &get_model('authorize');
		
		if ( $user_model->authorize($user_name,$password) ) {
			// 设置用户登录cookie信息
			$_id = authcode($user_name."|".$password,'ENCODE');
			set_cookie('U',$_id);
			header("Location: index.php?c=index");
		} else {
			header("Location: " . creat_url("",$this->config->get_item('site_url'),0,false) );
		}
	}
	
	/**
	 * 退出登录
	 */
	function loginout() {
		set_cookie('U',"",-1);
		header("Location: " . creat_url("",$this->config->get_item('site_url'),0,false) );
	}
}
